package com.tech.connect.huanzhewan;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ksy.common.utils.BaseAdapter;
import com.ksy.common.utils.BaseHolder;
import com.ksy.common.view.HLineDivider;
import com.tech.connect.R;
import com.tech.connect.activity.BaseActivity;
import com.tech.connect.activity.CityChooseActivity;

import java.util.ArrayList;
import java.util.List;

public class HuanZheWanHuHuanShenFenActivity extends BaseActivity {


    private RecyclerView recycler;
    private List<String> allList = new ArrayList<>();
    private BaseAdapter<String, BaseHolder> adapter;
    private String tagTitle;

    @Override
    protected boolean isShowHeadBar() {
        return false;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_huanzhewan_huhuanshenfen);
        Intent intent = getIntent();
        tagTitle = intent.getStringExtra("tagTitle");
        initView();
        initAdapter();
    }


    private void initView() {
        findViewById(R.id.ivBack).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.onBackPressed();
            }
        });
        TextView tvCity = findViewById(R.id.tvCity);
        tvCity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(CityChooseActivity.class);
            }
        });
        findViewById(R.id.tvPublish).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(PublishChangeInfoActivity.class);

            }
        });

        recycler = findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return true;
            }
        });
        recycler.addItemDecoration(new HLineDivider());
    }

    private void initAdapter() {
        if (adapter == null) {
            adapter = new BaseAdapter<String, BaseHolder>(R.layout.item_layout_huhuanshenfen, allList, 16) {
                @Override
                protected void convert(BaseHolder helper, int position) {
                    ImageView ivHead = helper.getView(R.id.ivHead);
                    TextView tvName = helper.getView(R.id.tvName);
                    TextView tvTag = helper.getView(R.id.tvTag);
                    TextView tvDate = helper.getView(R.id.tvDate);
                    TextView tvExtra = helper.getView(R.id.tvExtra);
                    tvTag.setText(tagTitle);
                }
            };
            adapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    jump2Activity(HuanZheWanShenFenViewActivity.class);
                }
            });
            recycler.setAdapter(adapter);
        }
        adapter.notifyDataSetChanged();
    }

}
